﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin.Win32;

namespace MyQQ
{
    public partial class RegisterForm : CCWin.CCSkinMain
    {
        public RegisterForm()
        {
            InitializeComponent();
        }

        private void skinButtom1_Click(object sender, EventArgs e)
        {
            if (skinTextBox1.Text == string.Empty || skinTextBox2.Text == string.Empty)
            {
                MessageBox.Show("禁止为空");
            }

            Message.Message msg = new Message.Message();
            msg.Type = Message.MessageType.Register;
            msg.Register = new Message.RegisterMessage(skinTextBox1.Text.Trim(), skinTextBox2.Text.Trim());
            msg.IP = new Message.IpMessage(Net.NetReciver.ip, Net.NetReciver.port);
            Net.NetSender.Sender.SendMessage(msg);
            Net.NetReciver.Listener.MessageArrived += GetInfo;
        }

        private void GetInfo(Message.Message msg)
        {
            if (msg.Type == Message.MessageType.Register)
            {
                if (msg.Register.success == true)
                {
                    var lg = new LoginForm(msg.Register.Name,msg.Register.Password);
                    this.Visible = false;
                    lg.Show();
                    lg.btnLogin_Click(null, null);
                }
            }
        }
    }
}
